﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DelegatesAndEvents
{
    class Person
    {
        private string firstName;
        private string lastName;
        private string gender;
        private string birthDate;
        public event FirstNameEventHandler FirstName1EventHandler;
        public event LastNameEventHandler LastName1EventHandler;

        public Person(string firstName, string lastName, string gender, string birthDate)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.gender = gender;
            this.birthDate = birthDate;
            FirstName1EventHandler += delegate(object sender, FirstNameEventArgs eventArgs)
            {
                Console.WriteLine("First Name Changed old name: {0}  new name: {1}",eventArgs.lastName,eventArgs.newName);
            };

            LastName1EventHandler += delegate(object sender, LastNameEventArgs eventArgs)
            {
                Console.WriteLine("Last Name Changed old name: {0}  new name: {1}", eventArgs.lastName, eventArgs.newName);
            };

            //FirstName1EventHandler += delegate(object sender, FirstNameEventArgs eventArgs)
            //{
            //    Console.WriteLine("First Name Changed");
            //};

            //FirstName1EventHandler += delegate(object sender, FirstNameEventArgs eventArgs)
            //{
            //    Console.WriteLine("First Name Changed");
            //};
        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                OnFirstNameChange(value );
                firstName = value;
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                OnLastNameChange(value);
                lastName = value;
            }
        }

        public string Gender
        {
            get
            {
                return gender;
            }
            set
            {
                gender = value;
            }
        }

        public string BirthDate
        {
            get
            {
                return birthDate;
            }
            set
            {
                birthDate = value;
            }
        }

        protected void OnFirstNameChange(string newFirstName) 
        {
            if(FirstName1EventHandler!=null)
            {
                FirstNameEventArgs args = new FirstNameEventArgs(this.firstName, newFirstName);
                FirstName1EventHandler(this, args);
            }
        }

        protected void OnLastNameChange(string newLastName)
        {
            if (LastName1EventHandler != null)
            {
                LastNameEventArgs args = new LastNameEventArgs(this.lastName, newLastName);
                LastName1EventHandler(this, args);
            }
        }

        protected void OnGenderChange()
        {

        }

        protected void OnBirthDateChange()
        {

        }

        public delegate void FirstNameEventHandler(object sender, FirstNameEventArgs eventArgs);

        public delegate void LastNameEventHandler(object sender, LastNameEventArgs eventArgs);

        public delegate void genderNameEventHandler();

        public delegate void birthDateNameEventHandler();
    }
}
